package com.example.demo.spi;

import sun.misc.Service;

import java.util.Iterator;
import java.util.ServiceLoader;

/**
 * @desc: <br/>
 * @author: Jingbo Hu<br/>
 * @time：2021年05⽉25⽇<br/>
 * @version：v1.0.0<br>
 */
public class SpiServiceTest {

    public static void main(String[] args) {

        ServiceLoader<HelloService> loaders = ServiceLoader.load(HelloService.class);
        for (HelloService helloService : loaders) {
            helloService.hello();
        }

        System.out.println("==========================");

        Iterator<HelloService> providers = Service.providers(HelloService.class);
        while (providers.hasNext()) {
            HelloService next = providers.next();
            next.hello();
        }
    }
}
